package net.dgg.rz.production.controller;

import net.dgg.framework.tac.utils.bean.DggRestResponse;
import net.dgg.framework.tac.utils.exception.DggBaseException;
import net.dgg.framework.tac.utils.web.commmon.DggBaseController;
import net.dgg.iboss.base.util.DesUtil;
import net.dgg.rz.common.constant.ScProductConstant;
import net.dgg.rz.common.utils.DataTableResponse;
import net.dgg.rz.production.dao.ProductOrderDao;
import net.dgg.rz.production.entity.ProductOrder;
import net.dgg.rz.production.exception.ProductOrderExcption;
import net.dgg.rz.production.service.ProductOrderService;
import net.dgg.tmd.foundation.platform.common.util.TranslateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/org_order")
public class OrgController extends DggBaseController {
    @Autowired
    private ProductOrderDao productOrderDao;
    @Autowired
    private TranslateUtil translateUtil;
    @Autowired
    private DesUtil desUtil;
    @Autowired
    private ProductOrderService productOrderService;


    /**
     * 事业部订单
     * @param model
     * @param status
     * @return
     */
    @RequestMapping(value = "/org_order_index.html")
    public String orgOrder(Model model, String status) {
        return "rzsc/org/org_order";
    }

    /**
     * json查询事业部生产订单
     * @param params
     */
    @RequestMapping(value = "/org_order_list")
    @ResponseBody
    public DggRestResponse orgOrderList(@RequestParam Map params) {
        try {
            List<ProductOrder> orgOrderList = productOrderService.orgOrderList(params);
            return new DataTableResponse().data(params, orgOrderList);
        } catch (DggBaseException e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 跨事业部移交页面
     *
     */
    @RequestMapping(value = "/transfer_org_order_page")
    public String transferOrgOrderPage(Model model,Long orderId) {
        try {
            productOrderService.transferOrgOrderPage(orderId, model);
            return "rzsc/org/transfer_org_order_page";
        } catch (DggBaseException e) {
            e.printStackTrace();
            throw new ProductOrderExcption(e.getMessage());
        } catch (Exception e) {
            throw new ProductOrderExcption(ScProductConstant.SYS_ERROR);
        }
    }
}
